home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-11-29 | 3.5 KB | 154 lines | [TEXT/PJMM] |
- unit TUserItem;
-
- { ⌐1986-1989 Bill Stackhouse }
- { Stackhouse Software }
- { Natick, MA 01760 }
-
- interface
-
- {$IFC UNDEFINED UseUserItem}
- {$SETC UseUserItem = FALSE}
- {$ENDC}
- {$IFC UseUserItem}
-
- uses
- TObject;
-
- const
- maxUserItems = 10;
-
- type
- TUserItem = object(TObject)
- numUserItems: 0..maxUserItems; {number of there user items}
- UserItem: array[1..maxUserItems] of record
- num: Integer; {number of item with this box}
- box: Rect; {bounds of user item}
- event: ProcPtr; {}
- select: ProcPtr; {}
- draw: ProcPtr; {}
- end;
- procedure TUserItem.Init;
- procedure TUserItem.Add (pBtn: Integer; {user item number}
- pDraw, pEvent, pSelect: ProcPtr; {}
- pBox: Rect); {}
- procedure TUserItem.Revise (curDialog: DialogPtr);
- procedure TUserItem.Mouse (curDialog: DialogPtr;
- theEvent: EventRecord);
- function TUserItem.Error: Integer;
- end;
-
- {$ENDC}
-
- implementation
-
- {$IFC UseUserItem}
-
- const
- Off = 0;
- On = 1;
-
- btnCtrlItem = 4;
- chkCtrlItem = 5;
- radCtrlItem = 6;
- editCtrlItem = 16;
-
- DialogGroupIgnored = -10; {too many groups, key, menus, or user items were added}
-
- type
- TSearch = (searching, found, endList);
-
- var
- globalError: Integer;
-
- function UserEvent (theDialog: DialogPtr;
- var theEvent: EventRecord;
- var item: Integer;
- proc: ProcPtr): Boolean;
- inline
- $205f, {movea.l (a7)+,a0 ; (a0) is a ptr to string, 4(a0) is mode}
- $4e90;
-
- procedure UserSelect (theDialog: DialogPtr;
- item: Integer;
- proc: ProcPtr);
- inline
- $205f, {movea.l (a7)+,a0 ; (a0) is a ptr to string, 4(a0) is mode}
- $4e90;
-
- procedure TUserItem.Init;
- begin
- globalError := noErr;
- SELF.numUserItems := 0;
- end; {TUserItem.Init}
-
- procedure TUserItem.Add (pBtn: Integer; {user item number}
- pDraw, pEvent, pSelect: ProcPtr; {}
- pBox: Rect); {}
- begin
- globalError := noErr;
- with SELF do
- if numUserItems < maxUserItems then
- begin
- numUserItems := numUserItems + 1;
- with UserItem[numUserItems] do
- begin
- num := pBtn;
- box := pBox;
- draw := pDraw;
- event := pEvent;
- select := pSelect;
- end;
- end
- else
- globalError := DialogGroupIgnored;
- end; {TUserItem.Add}
-
- procedure TUserItem.Revise (curDialog: DialogPtr);
- var
- i, j: Integer;
- theType: Integer;
- theHandle: Handle;
- theBox: Rect;
- begin
- globalError := noErr;
- for i := 1 to SELF.numUserItems do
- with SELF.UserItem[i] do
- begin
- GetDItem(curDialog, num, theType, theHandle, box);
- SetDItem(curDialog, num, theType, Handle(draw), box);
- end;
- end; {TUserItem.Revise}
-
- procedure TUserItem.Mouse (curDialog: DialogPtr;
- theEvent: EventRecord);
- var
- i: Integer;
- begin
- globalError := noErr;
- GlobalToLocal(theEvent.where); {because PtInRect wants it that way}
- with SELF do
- begin
- if numUserItems > 0 then
- for i := 1 to numUserItems do
- with UserItem[i] do
- if PtInRect(theEvent.where, box) then
- begin
- if event <> nil then
- begin
- if UserEvent(curDialog, theEvent, num, event) then
- UserSelect(curDialog, num, select);
- end;
- Leave;
- end;
- end;
- LocalToGlobal(theEvent.where); {because Dlog Mgr wants it that way}
- end; {TUserItem.Mouse}
-
- function TUserItem.Error: Integer;
- begin
- Error := globalError;
- end; {TUserItem.Error}
-
- {$ENDC}
-
- end.